package com.yhn.init.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yhn.init.common.BaseResponse;
import com.yhn.init.common.DeleteRequest;
import com.yhn.init.common.ResultUtils;
import com.yhn.init.model.dto.financialTransactions.FinancialTransactionsAddRequest;
import com.yhn.init.model.dto.financialTransactions.FinancialTransactionsQueryRequest;
import com.yhn.init.model.dto.financialTransactions.FinancialTransactionsUpdateRequest;
import com.yhn.init.model.vo.FinancialTransactionsVO;
import com.yhn.init.service.FinancialTransactionsService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * 收支记录
 *
 * @author yhnyhn123
 * @email 2236751002@qq.com
 * @date 2024-03-08 20:36:42
 */
@RestController
@RequestMapping("/financialtransactions")
public class FinancialTransactionsController {

    @Resource
    private FinancialTransactionsService financialTransactionsService;

    /**
     * 列表,分页
     */
    @GetMapping("/list")
    //@SaCheckPermissions("furniture/financialtransactions/list")
    public BaseResponse<Page<FinancialTransactionsVO>> listByPage(@RequestBody FinancialTransactionsQueryRequest financialTransactionsQueryRequest) {
        Page<FinancialTransactionsVO> page = financialTransactionsService.queryPage(financialTransactionsQueryRequest);
        return ResultUtils.success(page);
    }


    /**
     * 获取单个信息
     */
    @GetMapping("/info/{id}")
    //@SaCheckPermissions("furniture/financialtransactions/info")
    public BaseResponse<FinancialTransactionsVO> getInfoById(@PathVariable("id") Long id) {
        FinancialTransactionsVO financialTransactions = financialTransactionsService.getInfoById(id);

        return ResultUtils.success(financialTransactions);
    }


    /**
     * 保存
     */
    @PostMapping("/save")
    // @SaCheckPermissions("furniture/financialtransactions/save")
    public BaseResponse<Long> save(@RequestBody FinancialTransactionsAddRequest financialTransactionsAddRequest) {
        Long newId = financialTransactionsService.saveFinancialTransactions(financialTransactionsAddRequest);

        return ResultUtils.success(newId);
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    //@SaCheckPermissions("furniture/financialtransactions/update")
    public BaseResponse<Boolean> update(@RequestBody FinancialTransactionsUpdateRequest financialTransactionsUpdateRequest) {
        boolean result = financialTransactionsService.updateFinancialTransactions(financialTransactionsUpdateRequest);

        return ResultUtils.success(result);
    }


    /**
     * 删除
     */
    @PostMapping("/delete")
    //@SaCheckPermissions("furniture/financialtransactions/delete")
    public BaseResponse<Boolean> delete(@RequestBody DeleteRequest deleteRequest) {
        boolean result = financialTransactionsService.deleteById(deleteRequest);
        return ResultUtils.success(result);
    }

    /**
     * 批量删除
     */
    @PostMapping("/deleteBatch")
    //@SaCheckPermissions("furniture/financialtransactions/delete")
    public BaseResponse<Boolean> deleteBatch(@RequestBody Long[] ids) {
        boolean result = financialTransactionsService.deleteBatchByIds(ids);
        return ResultUtils.success(result);
    }
}
